package emulator.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import emulator.hardware.memory.MemoryBlockInterface;

public class ByteArrayWrapper implements MemoryBlockInterface {

	private byte [] data;
	
	public ByteArrayWrapper(byte [] data)
	{
		this.data = data;
	}
	
	@Override
	public void loadFromStream(InputStream file, int address, int size)
			throws IOException {
		for (int i = 0; i < size; i++)
		{
			int ch = file.read();
			if (ch < 0)
				return;
			data[address+i] = (byte)ch;
		}
	}

	@Override
	public byte[] getData() {
		return data;
	}

	@Override
	public void saveToStream(OutputStream file, int address, int size)
			throws IOException {
		file.write(data, address, size);
	}
}
